<template>
  <div id="all">
    <!-- 导航栏 -->
    <div>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple-light"></div>
        </el-col>
      </el-row>
    </div>
    <!-- 登录框 -->
    <div id="login">
      <el-form :label-position="labelPosition" :rules="rules" ref="loginForm" :model="loginForm">
        <div class="title">
          <span>登录</span>
        </div>
        <el-form-item prop="accountInfo">
          <el-input v-model="loginForm.accountInfo" placeholder="输入你的账号" icon="#xe665"></el-input>
          <div>
            <span></span>
          </div>
        </el-form-item>
        <el-form-item prop="accountPwd">
          <el-input type="password" v-model="loginForm.accountPwd" placeholder="输入你的密码" class=".icon-username"></el-input>
        </el-form-item>
        <div class="box_position">
          <a @click="skipPwd()" href="#">忘记密码</a>
        </div>

        <el-form-item>
          <el-button class="loginBtn1" type="primary" @click="submitForm()">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
// 导入传值中转站bus
import bus from "../bus.js";
export default {
  name: "login",

  data() {
    var validateAccount = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入账号"));
      } else {
        if (this.loginForm.checkAccount !== "") {
          this.$refs.loginForm.validateField("checkAccount");
        }
        callback();
      }
    };
    var validatePassword = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.loginForm.checkPassord !== "") {
          this.$refs.loginForm.validateField("checkPassword");
        }
        callback();
      }
    };
    return {
      labelPosition: "left",
      loginForm: {
        accountInfo: "",
        accountPwd: ""
      },
      //  向Index传的值
      toIndexForm: [],
      //  向Index传的值end
      rules: {
        accountInfo: [{ validator: validateAccount, trigger: "blur" }],
        adminPwd: [{ validator: validatePassword, trigger: "blur" }]
      }
    };
  },
  methods: {
    // 登录
    submitForm() {
      this.$post_form(this.$urlPath.user + "/account/Login", {
        accountInfo: this.loginForm.accountInfo,
        accountPwd: this.loginForm.accountPwd
      }).then(resp => {
        if (resp.code != 200) {
          // return this.$message.error(resp.message);
          return this.$message.error(resp);

        }
        window.localStorage.setItem("cicToken", resp.map.cicToken);
        this.toIndexForm = resp.map.account;

        // 向Index传值
        sessionStorage.setItem("toIndexForm", JSON.stringify(this.toIndexForm));
      
      // bus.$emit("toIndexForm", this.toIndexForm);
        this.$router.push({ path: "/index"});
        // 向Index传值end
      });
    },
    // 登录end

    skipPwd() {
      this.$router.push({ path: "/forgetPwd" });
    }
  }
};
</script>
<style lang="less">
@import "../assets/less/login.less";
.bg-purple-light {
  background: #007bffd9;
}
.grid-content {
  min-height: 80px;
}
.icon {
  width: 1em;
  height: 1em;
  vertical-align: 0em;
  fill: currentColor;
  overflow: hidden;
}
.box_position {
  position: relative;
  left: 180px;
  top: -10px;
  bottom: -10px;
}
</style>